package com.ruoyi.listen.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParam;
import com.ruoyi.listen.domain.ListenApply;
import com.ruoyi.listen.service.IListenApplyService;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 听课申请Controller
 * 
 * @author yepanpan
 * @date 2021-03-15
 */
@Api("听课申请管理")
@RestController
@RequestMapping("/listen/apply")
public class ListenApplyController extends BaseController
{
    @Autowired
    private IListenApplyService listenApplyService;

    /**
     * 查询听课申请列表
     */
    @ApiOperation("查询听课申请列表")   
    @PreAuthorize("@ss.hasPermi('listen:apply:my')")
    @GetMapping("/my")
    public TableDataInfo my(ListenApply listenApply)
    {
    	listenApply.setCreateBy(SecurityUtils.getUsername());
        startPage();
        List<ListenApply> list = listenApplyService.selectListenApplyList(listenApply);
        return getDataTable(list);
    }

    /**
     * 查询听课申请列表
     */
    @ApiOperation("查询听课申请列表")   
    @PreAuthorize("@ss.hasPermi('listen:apply:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListenApply listenApply)
    {
        startPage();
        List<ListenApply> list = listenApplyService.selectListenApplyList(listenApply);
        return getDataTable(list);
    }

    /**
     * 导出听课申请列表
     */
    @ApiOperation("导出听课申请列表")    
    @PreAuthorize("@ss.hasPermi('listen:apply:export')")
    @Log(title = "听课申请", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ListenApply listenApply)
    {
        List<ListenApply> list = listenApplyService.selectListenApplyList(listenApply);
        ExcelUtil<ListenApply> util = new ExcelUtil<ListenApply>(ListenApply.class);
        return util.exportExcel(list, "apply");
    }

    /**
     * 获取听课申请详细信息
     */
    @ApiOperation("获取听课申请详细信息")
    @ApiImplicitParam(name = "id", value = "听课申请ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('listen:apply:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(listenApplyService.selectListenApplyById(id));
    }

    /**
     * 新增听课申请
     */
    @ApiOperation("新增听课申请")
    @PreAuthorize("@ss.hasPermi('listen:apply:add')")
    @Log(title = "听课申请", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ListenApply listenApply)
    {
        return toAjax(listenApplyService.insertListenApply(listenApply));
    }

    /**
     * 修改听课申请
     */
    @ApiOperation("修改听课申请")  
    @PreAuthorize("@ss.hasPermi('listen:apply:edit')")
    @Log(title = "听课申请", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ListenApply listenApply)
    {
        return toAjax(listenApplyService.updateListenApply(listenApply));
    }

    /**
     * 删除听课申请
     */
    @ApiOperation("删除听课申请")
    @ApiImplicitParam(name = "id", value = "听课申请ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('listen:apply:remove')")
    @Log(title = "听课申请", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(listenApplyService.deleteListenApplyByIds(ids));
    }
    
    /**
     * 审核听课申请
     */
    @ApiOperation("审核听课申请")
    @ApiImplicitParam(name = "id", value = "听课申请ID", required = true, dataType = "int", paramType = "path") 
    @PreAuthorize("@ss.hasPermi('listen:apply:remove')")
    @Log(title = "听课申请", businessType = BusinessType.UPDATE)
	@GetMapping("/check/{ids}")
    public AjaxResult check(@PathVariable Long[] ids)
    {
        return toAjax(listenApplyService.checkListenApplyByIds(ids));
    }
    
}
